package com.eedi.framework.mail.controller.sys;

import com.eedi.framework.common.pojo.CommonResult;
import com.eedi.framework.common.pojo.PageResult;
import com.eedi.framework.common.util.object.BeanUtils;
import com.eedi.framework.mail.controller.sys.vo.log.MailLogPageReq;
import com.eedi.framework.mail.service.SysMailLogService;
import com.eedi.framework.mail.controller.sys.vo.log.MailLogResp;
import com.eedi.framework.mail.dal.dataobject.SysMailLogDO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.eedi.framework.common.pojo.CommonResult.success;

@Tag(name = "系统界面 - 邮件日志")
@RestController
@RequestMapping("/mail-log")
public class MailLogController {

    @Resource
    private SysMailLogService sysMailLogService;

    @GetMapping("/page")
    @Operation(summary = "获得邮箱日志分页")
    @PreAuthorize("@ss.hasPermission('sys:mail-log:query')")
    public CommonResult<PageResult<MailLogResp>> getMailLogPage(@Valid MailLogPageReq pageVO) {
        PageResult<SysMailLogDO> pageResult = sysMailLogService.getMailLogPage(pageVO);
        return success(BeanUtils.toBean(pageResult, MailLogResp.class));
    }

    @GetMapping("/get")
    @Operation(summary = "获得邮箱日志")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('sys:mail-log:query')")
    public CommonResult<MailLogResp> getMailTemplate(@RequestParam("id") Long id) {
        SysMailLogDO log = sysMailLogService.getMailLog(id);
        return success(BeanUtils.toBean(log, MailLogResp.class));
    }

}
